//
//  ConnectUsViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/19.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ConnectUsViewController.h"

@interface ConnectUsViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UILabel *placeholder;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *commitButton;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *phoneField;
@property (weak, nonatomic) IBOutlet UITextField *emilField;

@end

@implementation ConnectUsViewController
- (void)viewWillAppear:(BOOL)animated{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    _textView.delegate = self;
    _commitButton.layer.cornerRadius = 4*VerticalRatio();
}

- (IBAction)back:(id)sender {
    
    [self backBtn];
}


#pragma mark ==== 提交
- (IBAction)commitHandel:(id)sender {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    if ([Common getLoginStatus]) {
        [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"member"];
    }
    if ([Common dataIsNULL:_nameField.text]) {
        [CWHUDTips showTips:_nameField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_phoneField.text]) {
        [CWHUDTips showTips:_phoneField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_emilField.text]) {
        [CWHUDTips showTips:_emilField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_textView.text]) {
        [CWHUDTips showTips:_placeholder.text];
        return;
    }
     [dic setObject:_nameField.text forKey:@"name"];
     [dic setObject:_phoneField.text forKey:@"phone"];
    [dic setObject:_emilField.text forKey:@"email"];
    [dic setObject:_textView.text forKey:@"content"];
    [dic setObject:@"2" forKey:@"devicetype"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_userFeedbackinfo withHttpType:@"POST" withTag:GS_GS_userFeedbackinfo];
}

#pragma mark - <UITextViewDelegate>
- (void)textViewDidChange:(UITextView *)textView{
    
    if (self.textView.text.length > 0) {
        self.placeholder.hidden = YES;
    }else{
        self.placeholder.hidden = NO;
    }
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    
    if (tag==GS_GS_userFeedbackinfo) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
        
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    [self dismissWaitDialog];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
